package com.leetcode.algorithm.y22.m06;

import com.leetcode.algorithm.common.ListNode;

/**
 * 21. 合并两个有序链表
 * 
 * https://leetcode.cn/problems/merge-two-sorted-lists/
 * 
 * @author jie.deng
 *
 */
class Question0021Solution01 {

	public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
		ListNode list = null;
		if (list1 == null) {
			return list2;
		} else if (list2 == null) {
			return list1;
		}
		if (list1.val <= list2.val) {
			list = new ListNode(list1.val);
			list.next = mergeTwoLists(list1.next, list2);
		} else {
			list = new ListNode(list2.val);
			list.next = mergeTwoLists(list1, list2.next);
		}
		return list;
	}
	
	
}